# Contributor: Bart Ribbers <bribbers@disroot.org>
# Contributor: Danct12 <danct12@disroot.org>
# Contributor: Clayton Craft <clayton@craftyguy.net>
# Contributor: Rasmus Thomsen <oss@cogitri.dev>
# Maintainer: team/phosh <newbie13xd@gmail.com>
pkgname=phoc
pkgver=0.42.1
pkgrel=0
pkgdesc="wlroots based Phone compositor for the Phosh shell"
arch="all !s390x" # blocked by gnome-desktop
url="https://gitlab.gnome.org/World/Phosh/phoc"
license="GPL-3.0-only"
depends="
	dbus
	mutter-schemas
	gsettings-desktop-schemas
	"
_wlrootsmakedepends="
	eudev-dev
	hwdata-dev
	libcap-dev
	libdisplay-info-dev
	libseat-dev
	libxcb-dev
	xcb-util-image-dev
	xcb-util-renderutil-dev
	xcb-util-wm-dev
	xkeyboard-config-dev
	xwayland-dev
	"
makedepends="
	glib-dev
	gmobile-dev
	gnome-desktop-dev
	json-glib-dev
	libdrm-dev
	libinput-dev
	libxkbcommon-dev
	mesa-dev
	meson
	pixman-dev
	wayland-dev
	wayland-protocols
	$_wlrootsmakedepends
	"
checkdepends="xvfb-run"
subpackages="$pkgname-dbg"
options="!check" # Needs fullblown EGL
source="https://sources.phosh.mobi/releases/phoc/phoc-${pkgver/_/.}.tar.xz"
replaces="wlroots-phosh"
builddir="$srcdir/$pkgname-${pkgver/_/.}"

prepare() {
	default_prepare

	patch -Np1 < subprojects/packagefiles/wlroots/0001-Revert-layer-shell-error-on-0-dimension-without-anch.patch -d subprojects/wlroots
}

build() {
	abuild-meson \
		-Db_lto=true \
		-Dembed-wlroots=enabled \
		-Dtests="$(want_check && echo true || echo false)" \
		--default-library=static \
		. output
	meson compile -C output
}

check() {
	xvfb-run -a meson test --no-rebuild --print-errorlogs -C output
}

package() {
	DESTDIR="$pkgdir/" meson install --no-rebuild -C output
	install -Dm755 helpers/scale-to-fit \
		-t "$pkgdir"/usr/bin

	# remove unneeded wlroots dev. files
	rm -r "$pkgdir"/usr/include
	rm -r "$pkgdir"/usr/lib/libwlroots.a
	rm -r "$pkgdir"/usr/lib/pkgconfig
}

sha512sums="
f09502542597ed17e5fef6846bb9617da6dae8a096e5eb37b0f69b4d0a6bfbdf17454969ebe14abba8a77197831cd789925ad426137c948ca6290f4d5c74d785  phoc-0.42.1.tar.xz
"
